package net.zjitc.utils;

import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/11/8.
 */
public class ControllerUtils {
//获得包下面的所有的类对象
    public static List<Class> getAllClass(String packName) throws ClassNotFoundException {
          List<Class> list=new ArrayList();
          String packPath=packName.replace(".","/");
          URL url=Thread.currentThread().getContextClassLoader().getResource(packPath);
          String filePath=url.getPath();
          File file=new File(filePath);
          File[] files=file.listFiles();
          //遍历所有的文件，找类
        for(File f:files)
        {
            String fileName=f.getName();
            //对名字做处理，去掉扩展名.class net.zjitc.controller.ProductController
            String clazzname=packName+"."+fileName.substring(0,fileName.length()-6);
            Class clazz=Class.forName(clazzname);
            list.add(clazz);
        }
          return list;
    }
}
